package leetcode;

/**
 * @ author : HyoJoo-W
 * @ createDate : 2021-06-02 21:09
 * @ Description :
 */
public class ReverseInt32
{
    public static void main(String[] args)
    {
        System.out.println(reverse(1534236469));
    }

    public static int reverse(int x)
    {
        if (x == 0)
        {
            return x;
        }
        else if (x > 0)
        {
            StringBuilder stringBuilder = new StringBuilder(String.valueOf(x));
            stringBuilder.reverse();
            //if (stringBuilder.toString())
            Integer integer = Integer.valueOf(String.valueOf(stringBuilder));
            if (integer < Integer.MIN_VALUE || integer > Integer.MIN_VALUE)
            {
                return 0;
            }
            return integer;
        }
        else
        {
            String sx = Integer.toString(Math.abs(x));
            String res = "";
            for (int i = sx.length() - 1; i >= 0; i--)
            {
                res += sx.charAt(i);
            }
            return -Integer.parseInt(res);
        }
    }
}
